/*
  ******************************************************************************
  * @file    HAL_PMU.h
  * @version V1.0.0
  * @date    2022
  * @brief   Header file of PMU HAL module.
  ******************************************************************************
*/

#ifndef __HAL_PMU_H__
#define __HAL_PMU_H__

#include "hal.h" 



#define EXTI_LINE_LVD           (EXTI_LINE_16)



/**
  * @brief  IO wake-up source
  */
typedef enum
{
    PMU_WAKEUP1  = 0x00000001,  //PA9   
    PMU_WAKEUP2  = 0x00000002,  //PB0       
    PMU_WAKEUP3  = 0x00000004,  //PB12     
}PMU_WakeUpIo_t;




/**
  * @brief  Wait for an interrupt or event
  */

#define WAIT_FOR_INT                        (0x00000000U)  
#define WAIT_FOR_EVENT                      (0x00000001U)

/**
  * @brief  Lowpower mode
  */
#define PMU_CTL0_LPMS_STOP                  (0x00000000U)  
#define PMU_CTL0_LPMS_POWERDOWN             (0x00000001U)  


/**
  * @brief  LVD Voltage
  */
#define PMU_LVD_1V71                        ( 0x0U << PMU_CTRL1_LVD_SEL_Pos)
#define PMU_LVD_2V01                        ( 0x1U << PMU_CTRL1_LVD_SEL_Pos)  
#define PMU_LVD_2V23                        ( 0x2U << PMU_CTRL1_LVD_SEL_Pos)
#define PMU_LVD_2V43                        ( 0x3U << PMU_CTRL1_LVD_SEL_Pos)
#define PMU_LVD_2V51                        ( 0x4U << PMU_CTRL1_LVD_SEL_Pos)
#define PMU_LVD_2V73                        ( 0x5U << PMU_CTRL1_LVD_SEL_Pos)  
#define PMU_LVD_2V80                        ( 0x6U << PMU_CTRL1_LVD_SEL_Pos)
#define PMU_LVD_2V90                        ( 0x7U << PMU_CTRL1_LVD_SEL_Pos)

/**
  * @brief  LVD Filter
  */
#define PMU_LVD_FILTER_8                    ( 0x0U << PMU_CTRL1_FLT_TIME_Pos)
#define PMU_LVD_FILTER_16                   ( 0x1U << PMU_CTRL1_FLT_TIME_Pos)
#define PMU_LVD_FILTER_32                   ( 0x2U << PMU_CTRL1_FLT_TIME_Pos)
#define PMU_LVD_FILTER_64                   ( 0x3U << PMU_CTRL1_FLT_TIME_Pos)
#define PMU_LVD_FILTER_96                   ( 0x4U << PMU_CTRL1_FLT_TIME_Pos)
#define PMU_LVD_FILTER_128                  ( 0x5U << PMU_CTRL1_FLT_TIME_Pos)
#define PMU_LVD_FILTER_192                  ( 0x6U << PMU_CTRL1_FLT_TIME_Pos)
#define PMU_LVD_FILTER_255                  ( 0x7U << PMU_CTRL1_FLT_TIME_Pos)


void HAL_PMU_Init(void);

void HAL_PMU_EnterSleep(uint32_t mode);

void HAL_PMU_EnterStop(uint32_t mode);

void HAL_PMU_EnterPowerdownMode(uint32_t mode);

void HAL_PMU_WakeupIOInit(PMU_WakeUpIo_t wakeup_io);

void HAL_PMU_WakeupIODeInit(PMU_WakeUpIo_t wakeup_io);

uint32_t HAL_PMU_GetWakeupSource(void);

void HAL_PMU_LvdResetEnable(uint32_t voltage, uint32_t filter, uint32_t filter_en);

void HAL_PMU_LvdResetDisable(void);

void HAL_PMU_LvdIrqEnable(uint32_t voltage, uint32_t filter, uint32_t filter_en);

void HAL_PMU_StopWaitTime(uint32_t stopWaitTime);



#endif



